
package org.abbett.eskine.controller;

import org.abbett.eskine.model.CustomIdentity;
import org.abbett.eskine.entity.Page;
import org.abbett.eskine.dao.PageDao;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;

import org.jboss.seam.annotations.web.RequestParameter;

import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import javax.faces.event.ActionEvent;
import java.util.Map;
import java.util.List;

import org.abbett.eskine.service.EditEditPageSaveOutcome;
import org.abbett.eskine.service.EditService;


/**
 * Glue code to bind Add or Edit Page Service with the view framework (Seam). This class contains
 * a default implementation of the action methods. Please avoid reimplmenting the action methods in this class.
 * The purpose of this class is to declare properties which can be bound to the UI.
 * 
  * Create a new wiki page, or edit an existing one.
  *
 * Automatically generated by clickframes
 * 
 * @author Vineet Manohar
 */
public abstract class GeneratedEditController extends Controller {
 
    @In("#{pageDao}") 
    protected PageDao pageDao;


    
    @In("#{editPageService}")
	protected EditService editService;

	@SuppressWarnings("unused")
	private static final Log logger = LogFactory.getLog(GeneratedEditController.class);

	@In
	protected CustomIdentity identity;

    @Create
    public void init() {


        // initialize all file inputs
          // all inputs initialized here 
    }

	@RequestParameter

    /** ${pageParameter.description} */
    private String id;

    /** 
     * Get Page ID
     *  
     * @return Page ID
     */
    public String getId() {
       return this.id;
    }

    /**
     * Set Page ID
     *
     * @param id
     */
    public void setId(String id) {
        this.id = id;
    }



    /** Page loaded from param 'id' */
    private org.abbett.eskine.entity.Page page;

    /** 
     * Get Page loaded from param 'id'
     *  
     * @return Page loaded from param 'id'
     */
    public org.abbett.eskine.entity.Page getPage() {
       return this.page;
    }

    /**
     * Set Page loaded from param 'id'
     *
     * @param page
     */
    public void setPage(org.abbett.eskine.entity.Page page) {
        this.page = page;
    }




	/**
	 * This method should be called before the page is loaded
	 * 
	 * All the page parameters should be consumed in this method
	 */
    public void processPageParameters() {
        initPage();


          // if you need to add more code, override this method in the child class 
    }

 
    protected Page loadPage() {
        return pageDao.findByPrimaryKey(id);
    }
    
    protected void initPage() {
        // if page has not been initialized, initialize it now
        if (getPage() == null) {
            setPage(loadPage());
            
            if (getPage() != null) {
                // this entity is of type 'page'. 
                // there is a form on this page which updates an entity of type 'page'.
                // therefore, use this entity to prePopulate the inputs
                setEditPageTitle(getPage().getTitle());
                 setEditPageContent(getPage().getContent());
             }
         }

    }
 
	/** Title
	 *
 	 * Title
 	 */
   
	protected String editPageTitle;

  	@org.hibernate.validator.NotNull(message="Please enter a title.")
  	public String getEditPageTitle() {
	   return this.editPageTitle;
	}

	public void setEditPageTitle(String editPageTitle) {
		this.editPageTitle = editPageTitle;
	}
	/** Content
	 *
 	 * Content
 	 */
   
	protected String editPageContent;

	public String getEditPageContent() {
	   return this.editPageContent;
	}

	public void setEditPageContent(String editPageContent) {
		this.editPageContent = editPageContent;
	}



  
    /**
     *  Converts any form inputs bound to entities to entities, stores them in the map ready to 
     *  be passed to the service methods
     */
    public Map<String, Object> editPageForm() {
        Map<String, Object> map = describe();
         page.setTitle(toText(editPageTitle));
        page.setContent(toText(editPageContent));
        map.put("page", page);
        return map;
    }

 
   /**
    * Save
    *
    *     * Automatically generated by clickframes
    */
   public abstract EditEditPageSaveOutcome editPageSave();


    protected EditService.EditPageSaveResponse editPageSaveResponse;

    public EditService.EditPageSaveResponse getEditPageSaveResponse() {
        return editPageSaveResponse;
    }


    private static final long serialVersionUID = 1L;
}// clickframes::version=2696613158::clickframes